package com.hongxun.project.assets.iBoxes.controller;

import java.util.List;

import com.hongxun.project.assets.iLine.domain.ILine;
import com.hongxun.project.assets.iLine.service.IILineService;
import com.hongxun.project.assets.iPoint.domain.IPoint;
import com.hongxun.project.assets.iPoint.service.IIPointService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hongxun.framework.aspectj.lang.annotation.Log;
import com.hongxun.framework.aspectj.lang.enums.BusinessType;
import com.hongxun.project.assets.iBoxes.domain.IBoxes;
import com.hongxun.project.assets.iBoxes.service.IIBoxesService;
import com.hongxun.framework.web.controller.BaseController;
import com.hongxun.framework.web.page.TableDataInfo;
import com.hongxun.framework.web.domain.AjaxResult;
import com.hongxun.common.utils.poi.ExcelUtil;

/**
 * 箱 信息操作处理
 * 
 * @author hongxun
 * @date 2019-03-19
 */
@Controller
@RequestMapping("/assets/iBoxes")
public class IBoxesController extends BaseController
{
    private String prefix = "assets/iBoxes";
	
	@Autowired
	private IIBoxesService iBoxesService;
	@Autowired
	private IILineService iLineService;
	@Autowired
	private IIPointService iPointService;


	
	@RequiresPermissions("assets:iBoxes:view")
	@GetMapping()
	public String iBoxes()
	{
	    return prefix + "/iBoxes";
	}
	
	/**
	 * 查询箱列表
	 */
	@RequiresPermissions("assets:iBoxes:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(IBoxes iBoxes)
	{
		startPage();
        List<IBoxes> list = iBoxesService.selectIBoxesList(iBoxes);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出箱列表
	 */
	@RequiresPermissions("assets:iBoxes:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IBoxes iBoxes)
    {
    	List<IBoxes> list = iBoxesService.selectIBoxesList(iBoxes);
        ExcelUtil<IBoxes> util = new ExcelUtil<IBoxes>(IBoxes.class);
        return util.exportExcel(list, "iBoxes");
    }
	
	/**
	 * 新增箱
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存箱
	 */
	@RequiresPermissions("assets:iBoxes:add")
	@Log(title = "箱", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(IBoxes iBoxes)
	{		
		return toAjax(iBoxesService.insertIBoxes(iBoxes));
	}

	/**
	 * 修改箱
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		IBoxes iBoxes = iBoxesService.selectIBoxesById(id);
		IPoint pPoint = iPointService.selectIPointById(iBoxes.getPId());
//		ILine iLine = iLineService.selectILineById(iBoxes.getLineId());
		iBoxes.setPId(pPoint.getCode());
		mmap.put("iBoxes", iBoxes);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存箱
	 */
	@RequiresPermissions("assets:iBoxes:edit")
	@Log(title = "箱", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(IBoxes iBoxes)
	{		
		return toAjax(iBoxesService.updateIBoxes(iBoxes));
	}
	
	/**
	 * 删除箱
	 */
	@RequiresPermissions("assets:iBoxes:remove")
	@Log(title = "箱", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(iBoxesService.deleteIBoxesByIds(ids));
	}
	
}
